package com.ouc.pampas;
import io.terminus.common.exception.ServiceException;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class Executor<O>
{
  @Autowired(required=false)
  protected MessageSources messageSources;
  
  public abstract O exec(Service paramService, Map<String, Object> paramMap);
  
  protected Object unwrapResponse(O result)
  {
    if (result == null) {
      return null;
    }
    if ((result instanceof io.terminus.pampas.common.Response))
    {
      io.terminus.pampas.common.Response resp = (io.terminus.pampas.common.Response)result;
      if (resp.isSuccess()) {
        return resp.getResult();
      }
      if (this.messageSources != null) {
        throw new ServiceException(this.messageSources.get(resp.getError()));
      }
      throw new ServiceException(resp.getError());
    }
   
    return result;
  }
}
